package com.droidcar;

import java.util.ArrayList;

import act.droidcar.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Adaptador de listagem dos contatos armazenados no banco e retornados a partir de um ArrayList de ContatosBD
 */
public class AdapterListViewContatos extends BaseAdapter {

	 
    private LayoutInflater mInflater;
    private ArrayList<ContatosBD> itens;
 
    public AdapterListViewContatos(Context context, ArrayList<ContatosBD> itens) {
        this.itens = itens;
        mInflater = LayoutInflater.from(context);
    }
 
    /**
     * Retorna a quantidade de itens
     */
    public int getCount() {
        return itens.size();
    }
 
    /**
     * Retorna o item de acordo com a posicao dele na tela.
     */
    public ContatosBD getItem(int position) {
        return itens.get(position);
    }
 
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View view, ViewGroup parent) {
    	ContatosBD item = itens.get(position);
        view = mInflater.inflate(R.layout.item_listview, null);
 
        ((TextView) view.findViewById(R.id.text)).setText(       		
        		item.getHTC_CODIGO() + " - " + item.getHTC_MENSAGEM()        		
        		);
        ((ImageView) view.findViewById(R.id.imagemview)).setImageResource(R.drawable.ic_launcher);
        return view;
    }
}
